package com.icode.translate.startup;

import com.icode.translate.*;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: alexz
 * Date: 14-6-30
 * Time: 下午4:14
 * To change this template use File | Settings | File Templates.
 */
public class TranslateClient extends WebServiceGatewaySupport {

    public List<String> translateWord(String word) {
        TranslatorString request = new TranslatorString();
        request.setWordKey(word);

        TranslatorStringResponse response = (TranslatorStringResponse) getWebServiceTemplate().marshalSendAndReceive(request, new SoapActionCallback("http://WebXml.com.cn/TranslatorString"));
        ArrayOfString translatorStringResult = response.getTranslatorStringResult();
        return translatorStringResult.getString();
    }

    public List<String> translateSentence(String sentence) {
        TranslatorSentenceString request = new TranslatorSentenceString();
        request.setWordKey(sentence);

        TranslatorSentenceStringResponse response = (TranslatorSentenceStringResponse) getWebServiceTemplate().marshalSendAndReceive(request, new SoapActionCallback("http://WebXml.com.cn/TranslatorSentenceString"));
        ArrayOfString translatorSentenceStringResult = response.getTranslatorSentenceStringResult();
        return translatorSentenceStringResult.getString();
    }
}
